#!/bin/sh

DIR='/Applications/Nemesys/'

mkdir ${DIR}executer.app/Contents/logs

ln -s ${DIR}executer.app/Contents/config /Applications/Nemesys/gui.app/Contents/
ln -s ${DIR}executer.app/Contents/logs /Applications/Nemesys/gui.app/Contents/
ln -s ${DIR}executer.app/Contents/config /Applications/Nemesys/license.app/Contents/
ln -s ${DIR}executer.app/Contents/logs /Applications/Nemesys/license.app/Contents/
ln -s ${DIR}executer.app/Contents/Resources/cfg /Applications/Nemesys/license.app/Contents/Resources/

touch ${DIR}executer.app/Contents/logs/nemesys.log
chmod 666 ${DIR}executer.app/Contents/logs/nemesys.log

${DIR}license.app/Contents/MacOS/lnemesys

cat << EOF > /Library/LaunchDaemons/it.fub.nemesys.plist
<?xml version="1.0" encoding="UTF-8"?>
	<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
		"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
	<plist version="1.0">
	<dict>
		<key>Label</key>
		<string>it.fub.nemesys</string>
		<key>ProgramArguments</key>
		<array>
			<string>${DIR}executer.app/Contents/MacOS/executer</string>
		</array>
		<key>RunAtLoad</key>
		<true/>
	</dict>
	</plist>
EOF

launchctl load it.fub.nemesys
launchctl start it.fub.nemesys

exit 0

